import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    name: 'login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/index',
    name: 'index',
    redirect: '/home',
    component: () => import('../views/IndexView.vue'),
    children: [
      {
        path: '/home',
        name: 'home',
        component: () => import('../views/HomeView.vue')
      },
      {
        path: '/productClassify',
        name: 'productClassify',
        component: () => import('../views/ProductInfo/ProductClassify.vue')
      },
      {
        path: '/productInfo',
        name: 'productInfo',
        component: () => import('../views/ProductInfo/ProductInfo.vue')
      },
      {
        path: '/productTree',
        name: 'productTree',
        component: () => import('../views/ProductInfo/ProductTree.vue')
      },
      {
        path: '/ordermanage',
        name: 'ordermanage',
        component: () => import('../views/OrderManage/OrderManage.vue')
      },
      {
        path: '/neworder',
        name: 'neworder',
        component: () => import('../views/OrderManage/NewOrder.vue')
      },
      {
        path: '/purchaseorder',
        name: 'purchaseorder',
        component: () => import('../views/OrderManage/PurchaseOrder.vue')
      },
      {
        path: '/returnorder',
        name: 'returnorder',
        component: () => import('../views/OrderManage/ReturnOrder.vue')
      },
      {
        path: '/orderdetail',
        name: 'orderdetail',
        component: () => import('../views/OrderManage/OrderDetail.vue')
      },
      {
        path: '/customermanage',
        name: 'customermanage',
        component: () => import('../views/CustomerManage/CustomerManage.vue')
      },
      {
        path: '/customercity',
        name: 'customercity',
        component: () => import('../views/CustomerManage/CustomerCity.vue')
      },
      {
        path: '/productcontrol',
        name: 'productcontrol',
        component: () => import('../views/ToMoreTable/ProductControl.vue')
      },
      {
        path: '/approvalprocess',
        name: 'approvalprocess',
        component: () => import('../views/ProcessManage/ApprovalProcess.vue')
      },
      {
        path: '/initiateprocess',
        name: 'initiateprocess',
        component: () => import('../views/ProcessManage/InitiateProcess.vue')
      },
      {
        path: '/mytask',
        name: 'mytask',
        component: () => import('../views/ProcessManage/MyTask.vue')
      },
      {
        path: '/databaseaccess',
        name: 'databaseaccess',
        component: () => import('../views/DataBase/DatabaseAccess.vue')
      },
      {
        path: '/testpage',
        name: 'testpage',
        component: () => import('../views/TestPage/TestPage.vue')
      },
      {
        path: '/usermanage',
        name: 'usermanage',
        component: () => import('../views/UserManage/UserManage.vue')
      },
      {
        path: '/authorityManage',
        name: 'authorityManage',
        component: () => import('../views/UserManage/AuthorityManage.vue')
      },
      {
        path: '/roleManagement',
        name: 'roleManagement',
        component: () => import('../views/UserManage/RoleManage.vue')
      },
      {
        path: '/codegeneration',
        name: 'codegeneration',
        component: () => import('../views/CodeGeneration/CodeGeneration.vue')
      },
      {
        path: '/menusettings',
        name: 'menusettings',
        component: () => import('../views/SystemManagement/MenuSettings.vue')
      },
      {
        path: '/selectsettings',
        name: 'selectsettings',
        component: () => import('../views/SystemManagement/SelectSettings.vue')
      },
      {
        path: '/logmanagement',
        name: 'logmanagement',
        component: () => import('../views/LogManagement/LogManagement.vue')
      },
    ]
  },
  {
    path: '/hadoop',
    name: 'hadoop',
    component: () => import('../views/HeaderNav/Hadoop.vue')
  },
  {
    path: '/framework',
    name: 'framework',
    redirect:'/startup',
    component: () => import('../views/HeaderNav/Framework.vue'),
    children: [
      {
        // 项目启动与发布
        path:'/startup',
        name: 'startup',
        redirect:'/a',
        component: () => import('../views/HeaderNav/Framework/ProjectStartup.vue'),
        children: [
          {
            path:'/a',
            name:'a',
            component: () => import('../views/HeaderNav/ProjectStartup/A.vue'),
          },
          {
            path:'/b',
            name:'b',
            component: () => import('../views/HeaderNav/ProjectStartup/B.vue'),
          },
          {
            path:'/c',
            name:'c',
            component: () => import('../views/HeaderNav/ProjectStartup/C.vue'),
          },
          {
            path:'/d',
            name:'d',
            component: () => import('../views/HeaderNav/ProjectStartup/D.vue'),
          },
          {
            path:'/e',
            name:'e',
            component: () => import('../views/HeaderNav/ProjectStartup/E.vue'),
          },
          {
            path:'/f',
            name:'f',
            component: () => import('../views/HeaderNav/ProjectStartup/F.vue'),
          },
          {
            path:'/g',
            name:'g',
            component: () => import('../views/HeaderNav/ProjectStartup/G.vue'),
          },
          {
            path:'/h',
            name:'h',
            component: () => import('../views/HeaderNav/ProjectStartup/H.vue'),
          }
        ]
      },
      {
        // 代码生成
        path:'/code',
        name: 'code',
        component: () => import('../views/HeaderNav/Framework/CodeGeneration.vue'),
      },
      {
        // 组件api
        path:'/api',
        name: 'api',
        component: () => import('../views/HeaderNav/Framework/ComponentApi.vue'),
      },
      {
        // 前端开发
        path:'/before',
        name: 'before',
        component: () => import('../views/HeaderNav/Framework/BeforeDevelopment.vue'),
      },
      {
        // 后台开发
        path:'/after',
        name: 'after',
        component: () => import('../views/HeaderNav/Framework/AfterDevelopment.vue'),
      },
      {
        // 移动端
        path:'/mobile',
        name: 'mobile',
        component: () => import('../views/HeaderNav/Framework/MobileTerminal.vue'),
      },
      {
        // 常见问题
        path:'/questions',
        name: 'questions',
        component: () => import('../views/HeaderNav/Framework/Questions.vue'),
      },
      {
        // 更新记录
        path:'/update',
        name: 'update',
        component: () => import('../views/HeaderNav/Framework/Update.vue'),
      },
    ]
  },

]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})
// 添加路由守卫
router.beforeEach((to, from, next) => {
  if (to.path == '/') {
    // 登录页直接放行
    next()
  } else {
    // 其他页先验证是否有token
    if (sessionStorage.getItem('token')) {
      next()
    } else {
      // 验证失败跳回到登录页
      alert('请先登录！')
      next('/')
    }
  }
})
export default router
